/**
 * 要深度合并的对象，材料对象
 * 返回深度合并的对象
 * 即使是数组对象也可以深度合并
 * 合并优先级为前者大于后者
 */
function depthAssign(obj, ...objs) {
  objs.forEach(val => {
    for (let attr in val) {
      if (obj[attr]) {
        if (typeof obj[attr] === 'object') {
          let oj = obj[attr]
          if (oj instanceof Array) {
            oj.forEach((element, i) => {
              if (typeof element === 'object') oj[i] = depthAssign(element, val[attr][i])
            })
          } else {
            oj = depthAssign(oj, val[attr])
          }
        }
      } else {
        obj[attr] = val[attr]
      }
    }
  })
  return obj;
}
let obj = {
  eject(num = 0) {
    if (num == 0) {
      this.success = function (config) {
        return config
      }
      this.error = function (error) {
        return Promise.reject(error)
      }
    } else if (num == 1) {
      this.success = function (config) {
        return config
      }
    } else {
      this.error = function (error) {
        return Promise.reject(error)
      }
    }
  },
  use(resolve, reject) {
    if (resolve) this.success = resolve;
    if (reject) this.error = reject;
  },
  success(config) {
    return config
  },
  error(error) {
    return Promise.reject(error);
  }
}
let response = depthAssign({}, obj)
let request = depthAssign({}, obj);
export default {
  response,
  request
}